<?php
    require "../init.php";

    if(empty($_SESSION['admin'])){
        admin_redirect("请登录",3,ADMIN_ROOT_URL . "login.php");
        die;
    }

    if(($_SESSION['admin']['type'] != 0) && ($_SESSION['admin']['type'] != 1)){
        admin_redirect('您没有权限');die;
    }

    $act = $_GET["act"];

    switch($act){
        case 'send' :
            //获取订单id
            $order_id = $_GET['id'];
            //获得该订单的付款状态
            $pay_status = $_GET['pay_status'];
            //如果未付款,则不能发货
            if($pay_status ==0 ){
                admin_redirect('未付款,不能发货');die;
            }
            $sql = "select goods_id,qty from ".PRE."ordergoods where order_id = '$order_id' ";
            $goods_list = query($link, $sql);
            //把每一件商品的库存量减去发出去的该商品的库存量
            foreach ($goods_list as $item) {
                $goods_id = $item['goods_id'];
                $qty = $item['qty'];
                $sql = "update ".PRE."goods set stock = stock - $qty where id = '$goods_id'";
                execute($link,$sql);
            }
            //把该订单的订单状态,改为已发货
            $sql = "update ".PRE."order set order_status = 1 where id = '$order_id'";
            $res = execute($link,$sql);
            if($res){
                admin_redirect("发货成功");die;
            }
            break;
    }







?>